﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using MobilnyDostawca.Repositories;

namespace MobilnyDostawca
{
    public partial class Nadzorcy : IValidatableObject
    {
        public bool IsValid { get; set; }
        
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            IsValid = true;

            if (this.Login == null)
            {
                IsValid = false;
                yield return new ValidationResult("Login jest wymagany");
            }
            else if (!Repository.IsTheSupervisorLoginCorrect(this.Login))
            {
                IsValid = false;
                yield return new ValidationResult("Login nie jest poprawny");
            }
            if (this.Haslo == null)
            {
                IsValid = false;
                yield return new ValidationResult("Hasło jest wymagane");
            }
            else if (HttpContext.Current.Request.Url.ToString().Contains("ChangePassword") && !Repository.IsTheSupervisorPasswordCorrect(this.Login, this.Haslo))
            {
                IsValid = false;
                yield return new ValidationResult("Hasło nie jest poprawne");
            }
        }
    }
}